<script>
import {defineComponent} from 'vue'

export default defineComponent({
    name: "newTicket",
    data() {
        return {
            handleList: [
                {
                    label:'手工开票',
                    value:'1'
                },
                {
                    label:'图形开票',
                    value:'2'
                },
                {
                    label:'调用典型票',
                    value:'3'
                },
                {
                    label:'专家库开票',
                    value:'4'
                },
                {
                    label:'调用历史操作票',
                    value:'5'
                },
            ],
            selectedRows:[],
            localnewTicket:false,
            currenHandle:'',
            ws:null,
        }
    },
    methods:{
        close(){
            this.$emit('DialogClose')
        },
        selectTicket(){
            if (this.currenHandle===''){
                this.$message.error('请选择开票方式')
                return
            }
            if (this.currenHandle==='图形开票'){
                this.ws.send(JSON.stringify({"cmd":"kpczState","state":"1"}))
                return;
            }
            this.$emit('selectTicket',this.currenHandle)
            this.localnewTicket = false
            this.$message.success(`当前进入${this.currenHandle}`)

        },
    },
    props:{
        newTicket:{
            type:Boolean,
            default:false
        }
    },
    watch: {
        newTicket(newVal) {
            this.localnewTicket = newVal;
            if (newVal&&!this.ws){
                    this.ws=this.$store.state.webSocket;
                    this.ws.addEventListener('message', (event) => {
                        let data = JSON.parse(event.data);
                        if (data.cmd==='kpczState'&&data.state==='1'){
                            this.$emit('selectTicket',this.currenHandle)
                            this.localnewTicket = false
                            this.$message.success(`当前进入${this.currenHandle}`)
                        }
                    });


            }
        }
    },
})
</script>

<template>
    <el-dialog title="生成操作票"   :close-on-click-modal="false"
    :close-on-press-escape="false"  :visible.sync="localnewTicket" width="20rem" @close="close" custom-class="switchPatrolDialog"  >
        <div>
            <fieldset style="width: 100%;border: 1px solid #666; border-radius: 5px;padding: 2rem;box-sizing: border-box">
                <legend style="color: white;margin-left: -1rem;font-size: 14px">开票方式</legend>
            <el-radio-group v-model="currenHandle" style="display: flex; gap: 10px;flex-direction: column">
                <el-radio v-for="item in handleList" :key="item.value" :label="item.label" style="color: #fff">{{ item.label }}</el-radio>
            </el-radio-group>
            </fieldset>
        </div>
        <div class="btns">
            <el-button @click="close" style="margin-left: auto" size="mini">取消</el-button>
            <el-button  @click="selectTicket" size="mini">确定</el-button>
        </div>

    </el-dialog>
</template>

<style scoped lang="less">
.el-button{
  color: #ebeff0;
  background: linear-gradient(#176575,#07283f);
  border:0;
  box-shadow: 0 -2px 0 rgba(16, 164, 195, .8);
  width: 8rem;
}


.btns{
  margin-top: 1rem;
  display: flex;
    margin-bottom: 1rem;
}
</style>
